using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel;
using ResourceBlender.Core;

namespace ResourceBlender.Express {
    /// <summary>
    /// An element used in an application
    /// </summary>
    public class ObservableElement : RBElement, INotifyPropertyChanged {
        private ObservableResource resource;
        /// <summary>
        /// Gets or sets the resource the element uses.
        /// </summary>
        /// <value>The resource.</value>
        public ObservableResource Resource {
            get { return resource; }
            set {
                resource = value;
                OnPropertyChanged("Resource");
            }
        }

        /// <summary>
        /// Initializes a new <see cref="ObservableElement"/>.
        /// </summary>
        public ObservableElement()
            : base() {
            this.resource = new ObservableResource();
        }

        /// <summary>
        /// Initializes a new <see cref="ObservableElement"/>.
        /// </summary>
        /// <param name="id">The ID.</param>
        /// <param name="name">The name.</param>
        /// <param name="bundleId">The bundle ID.</param>
        /// <param name="bundleName">Name of the bundle.</param>
        /// <param name="comment">The comment.</param>
        public ObservableElement(int id, string name, string bundleId, string bundleName, string comment)
            : base(id, name, bundleId, bundleName, comment) {
            this.resource = new ObservableResource();
        }

        public event PropertyChangedEventHandler PropertyChanged;
        protected virtual void OnPropertyChanged(string strPropertyName) {
            if(PropertyChanged != null) {
                PropertyChanged(this, new PropertyChangedEventArgs(strPropertyName));
            }
        }

        internal ObservableElement Clone() {
            ObservableElement clone = new ObservableElement() {
                Application = this.Application,
                BundleID = this.BundleID,
                BundleName = this.BundleName,
                Comment = this.Comment,
                ID = this.ID,
                Name = this.Name,
                Resource = this.Resource.Clone()
            };
            return clone;
        }

        public RBElement ToRBElement() {
            RBElement clone = new RBElement() {
                Application = this.Application,
                BundleID = this.BundleID,
                BundleName = this.BundleName,
                Comment = this.Comment,
                ID = this.ID,
                Name = this.Name,
                Resource = this.Resource.ToRBResource()
            };
            return clone;
        }
    }
}
